﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 三国杀
{
    public partial class QQUserAdd : Form
    {
        public QQUserAdd()
        {
            InitializeComponent();
            this.MouseDown += QQUserAdd_MouseDown;
            this.MouseUp += QQUserAdd_MouseUp;
            this.MouseMove += QQUserAdd_MouseMove;
        }

        Point mousePosition;

        Point formPosition;

        bool isMouseDown = false;//是否按下


        private void QQUserAdd_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;

            mousePosition = Control.MousePosition;  //鼠标位置

            formPosition = this.Location;   //窗体左上角位置
        }

        private void QQUserAdd_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }

        private void QQUserAdd_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePoint = Control.MousePosition;   //移动的位置
            if (isMouseDown)
            {
                this.Location = new Point(mousePoint.X - mousePosition.X + formPosition.X, mousePoint.Y - mousePosition.Y + formPosition.Y);
            }
        }

        public int imagenum;
            public string Name;
            public string Qm;


        private void QQUserAdd_Load(object sender, EventArgs e)
        {
            this.QQname.Text = Name;
            this.QQqm.Text = Qm;
            this.pictureBox1.BackgroundImage = imageList1.Images[imagenum];
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void pictureBox5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"确定要添加 {Name} 为好友吗？", "添加好友",
              MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // 获取主窗体实例
                QQMain mainForm = Application.OpenForms.OfType<QQMain>().FirstOrDefault();

                if (mainForm != null)
                {
                    // 添加到好友列表
                    mainForm.FriendsList.Add(new QQMain.FriendInfo
                    {
                        ImageIndex = imagenum,
                        Name = Name,
                        Signature = Qm
                    });

                    // 刷新好友显示
                    mainForm.DisplayFriends();
                }

                MessageBox.Show("好友添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
